import token
from unittest import result

base_url = "http://120.55.14.193:8899"
HOST = "120.55.14.193"
USER = 'root'
PWD = '123456'
import pymysql
import pytest
import allure
import requests
@allure.feature("CRMEB项目")
class TestCRMEB:
        base_url = "http://120.55.14.193:8899"

        @pytest.fixture()
        def login(self):
            response = requests.post(self.base_url + "/adminapi/login",
                                     json={"account":"admin","pwd":"123456","key":"6566a3c67d9a3","captchaType":"blockPuzzle","captchaVerification":""})
            assert response.json()['msg'] == 'ok'
            assert response.status_code == 200
            with open('token.txt', 'w', encoding='utf-8') as f:
                f.write(response.json()['data']['token'])
                print(f"Logged in with token: {token}")
                yield token
                # 清理操作，例如删除 token 文件或数据库中的记录
                print("Logged out")

        @allure.story("客户分组")
        def test_user_group(self, login):
            with open("token.txt", 'r', encoding='utf-8') as f:
                result = f.read()
            response = requests.post(self.base_url+"/adminapi/user/user_group/list?page=1&limit=15",header={"Authori-zation: Bearer"+str(result)})
            assert response.json()['msg'] == 'ok'
            assert response.status_code == 200

        @allure.story("添加分组")
        def test_add_group(self,test_user_group):
            with open("token.txt", 'w', encoding='utf-8') as f:
                result = f.read()
                response = requests.post(self.base_url +"/adminapi/user/user_group/add/0",header={"Authori-zation: Bearer"+str(result)})
                assert response.json()['msg'] == 'ok'
               assert response.status_code == 200



